package top.hekun.study.shell.config;


import org.jline.utils.AttributedString;
import org.jline.utils.AttributedStyle;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.shell.jline.PromptProvider;

/**
 * 配置shell 基础信息
 */
@SpringBootConfiguration
public class ShellPromptConfig implements PromptProvider {

    private String promot = "请输入命令";
    private int i = 0;

    /**
     * 配置提示符, 默认值为 shell:>
     *
     * @return
     */
    @Override
    public AttributedString getPrompt() {
        // 设置命令提示符字体样式 黑体前景绿色
        AttributedStyle promotStyle = getAttributedString(++i);
        // 返回命令提示符
        return new AttributedString(promot + " " + i + " :==> ", promotStyle);
    }

    private AttributedStyle getAttributedString(int i) {
        switch (i % 7) {
            case 0:
                return AttributedStyle.DEFAULT.foreground(AttributedStyle.BLACK);
            case 1:
                return AttributedStyle.BOLD.foreground(AttributedStyle.RED);
            case 2:
                return AttributedStyle.BOLD_OFF.foreground(AttributedStyle.GREEN);
            case 3:
                return AttributedStyle.INVERSE.foreground(AttributedStyle.YELLOW);
            case 4:
                return AttributedStyle.INVERSE_OFF.foreground(AttributedStyle.BLUE);
            case 5:
                return AttributedStyle.HIDDEN.foreground(AttributedStyle.MAGENTA);
            case 6:
                return AttributedStyle.HIDDEN_OFF.foreground(AttributedStyle.CYAN);
            default:
                return AttributedStyle.DEFAULT.foreground(AttributedStyle.WHITE);
        }
    }
}
